﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UserClient.ServiceReference1;

namespace UserClient
{
    public partial class RouteWindow : Form
    {
        private StandardServiceClient stdService = new StandardServiceClient();
        private Action selectRoute;

        public RouteWindow(Action selectRoute, string from, string to, string[] priceAndTime, List<WCFPlane> planelist, WCFCompleteRoute completeRoute)
        {
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            InitializeComponent();

            string[] destinationer = completeRoute.BestAllDestinations.Split(' ');
            fromTextBox.Text = from;
            toTextBox.Text = to;
            timeTextBox.Text = priceAndTime[1] + " hour(s)";
            priceLabel.Text += priceAndTime[0] + " DKK";
            routeInfoPanel.Show();
            this.selectRoute = selectRoute;
            depLabel.Text += planelist[0].Departure.TimeOfDay;
            arrLabel.Text += planelist[planelist.Count - 1].Arrival.TimeOfDay;

            for (int x = 0; x < destinationer.Length - 1; x++)
            {
                if (subDestinationTextBox.Text.Length == 0)
                {
                    subDestinationTextBox.Text = destinationer[x];
                    subDestinationTextBox.AppendText("\r\n- ARR: " + planelist[x].Arrival.TimeOfDay);
                    subDestinationTextBox.AppendText("\r\n- DEP: " + planelist[x + 1].Departure.TimeOfDay);
                    
                }
                else
                {
                    subDestinationTextBox.AppendText("\r\n" + destinationer[x]);
                    subDestinationTextBox.AppendText("\r\n- ARR: " + planelist[x].Arrival.TimeOfDay);
                    subDestinationTextBox.AppendText("\r\n- DEP: " + planelist[x + 1].Departure.TimeOfDay);
                }

            }
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void acceptButton_Click(object sender, EventArgs e)
        {
            selectRoute();
            this.Close();
        }
    }
}
